package cn.bdqn.service.impl;

import cn.bdqn.bean.result.Page;
import cn.bdqn.domain.Druginfo;
import cn.bdqn.mapper.DruginfoMapper;
import cn.bdqn.service.DruginfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "druginfoServie")
public class DruginfoServiceImpl implements DruginfoService {

    @Autowired
    private DruginfoMapper druginfoMapper;

    @Override
    public List<Druginfo> queryAll() {
        return druginfoMapper.selectAll();
    }

    @Override
    public Page<Druginfo> queryPage(Integer startNum) {
        Page page=new Page();

        Integer pageSize = page.getPageSize();
        //判断当前是第几页,如果startNum为空
        PageHelper.startPage(startNum != 0 ? startNum:1,pageSize);
        List<Druginfo> druginfoList= druginfoMapper.selectPage();

        //分页
        PageInfo<Druginfo> pageInfo=new PageInfo<Druginfo>(druginfoList);
        //获取分页之后的数据
        page.setMenuList(pageInfo.getList());
        //总记录数
        page.setTotalRecord((int)pageInfo.getTotal());
        System.out.println(page);
        //返回分页对象
        return  page;
    }

    @Override
    public Druginfo queryById(Integer id) {
        return druginfoMapper.selectByPrimaryKey(id);
    }

    public Druginfo queryByNo(Integer drugNo){
        return druginfoMapper.selectByNo(drugNo);
    }

    @Override
    public void addSelective(Druginfo druginfo) {
        druginfoMapper.insertSelective(druginfo);
    }

    @Override
    public void changeByPrimaryKeySelective(Druginfo druginfo) {
        druginfoMapper.updateByPrimaryKeySelective(druginfo);
    }

    @Override
    public void removeById(Integer id) {
        druginfoMapper.deleteByPrimaryKey(id);
    }
}
